package com.csust.automaticteach.utils;


import java.time.LocalDateTime;

/**
 * @ClassNameRedisIdWorker
 * @Description redis全局Id生成器
 * @Author钰玟
 * @Date2025/7/23 下午7:43
 * @Version 1.0
 **/
//@Component
public class RedisIdWorker {

//    private final StringRedisTemplate stringRedisTemplate;
//
//    public RedisIdWorker(StringRedisTemplate stringRedisTemplate) {
//        this.stringRedisTemplate = stringRedisTemplate;
//    }
//
//    private static final long BEGIN_TIMESTAMP = 1735689600L;
//
//    private static final long COUNT_BITS = 32;
//    public long nextId(String keyPrefix) {
//        //1.得到时间戳
//        LocalDateTime now = LocalDateTime.now();
//        long nowSecond = now.toEpochSecond(java.time.ZoneOffset.UTC);
//        long timestamp = nowSecond - BEGIN_TIMESTAMP;
//
//        //2.获取序列号
//        //2.1 获取当前日期
//        String date = now.format(java.time.format.DateTimeFormatter.ofPattern("yyyyMMdd"));
//        //自增长
//        long count = stringRedisTemplate.opsForValue().increment("icr:" + keyPrefix + ":" + date);
//        //3.拼接并返回
//        return timestamp << COUNT_BITS | count;
//    }

}
